package com.afu.demo;

import java.util.Comparator;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.stream.Stream;

/**
 * ClassName: Demo5
 * Package: com.afu.demo
 * Description:
 *
 * @Author zxf
 * @Create 2024/2/20 20:26
 * @Version 1.0
 */
public class Demo5 {

    public static void main(String[] args) {
        /*Runnable r = new Runnable(){
            @Override
            public void run() {
                System.out.println("hello World");
            }
        };
        r.run();

        Runnable r2 = ()->{System.out.println(1);};
        r2.run();


        Consumer c1 = new Consumer<String>() {
            @Override
            public void accept(String o) {
                System.out.println(o);
            }
        };
        c1.accept("Consumer1 accept ====");

        Consumer c2 = (x1) -> {
            System.out.println(x1);
        };
        c2.accept("c2 accept x2");


        Consumer c3 = x->{
            System.out.println(x);
        };

        c3.accept("333");


        Comparator<Integer> com1 = new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                System.out.println(o1);
                System.out.println(o2);
                return o1.compareTo(o2);
            }
        };
        System.out.println(com1.compare(12,21));
        System.out.println("*****************************");
        //语法格式五使用后
        Comparator<Integer> com2 = (o1,o2) -> {
            System.out.println(o1);
            System.out.println(o2);
            return o1.compareTo(o2);
        };
        System.out.println(com2.compare(12,6));




        Comparator<Integer> co3 = (x1,x2) -> {
            return x1.compareTo(x2);
        };

        System.out.println( co3.compare(1,2));

        Comparator<Integer> co4 = (x,y)->x.compareTo(y);
        System.out.println(co3.compare(21,10));
        System.out.println("----------------------------");
        MyComparator<Integer> myComparator = (a,b) -> {
            System.out.println(a+b);
        };
        myComparator.method1(1,2);*/


        String friends[] = { "lisa", "bily", "kessy" };
        try {
            for (int i = 0; i < 5; i++) {
                System.out.println(friends[i]);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("index err");
        }
        System.out.println("\nthis is the end");
    }

}
